#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mem(x) memset(x,0,sizeof(x))
#define endl "\n"
#define printYes cout << "Yes\n"
#define printYES cout << "YES\n"
#define printNo cout << "No\n"
#define printNO cout << "NO\n"
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,j,k) for (int i=(j);i<=(k);i++)
#define per(i,j,k) for (int i=(j);i>=(k);i--)
#define pcnt(x) __builtin_popcount(x)
mt19937 rnd(time(0));
template<class T>void chkmin(T&x,T y){x=min(x,y);}
template<class T>void chkmax(T&x,T y){x=max(x,y);}

const ll inf=1000000000000000000; 
//const ll inf=1000000000;
//const ll mod=998244353;
const ll mod=1000000007;

bool _st;

const int N=305;
int n,m; 
int a[N][N],b[N][N],ans[N][N];
bool flag;
inline int read()
{
	char x;
	cin >> x;
	return (x=='1');
}
void rotate()
{
	rep(i,0,n-1) rep(j,0,m-1) b[i][j]=a[i][j];
	rep(i,0,n-1) rep(j,0,m-1) a[i][j]=b[n-1-i][m-1-j];
}
int dp[N][1<<17];
inline void add(int &x,int y)
{
	x+=y;
	if (x>=mod) x-=mod;
}
inline void del(int &x,int y)
{
	x-=y;
	if (x<0) x+=mod;
}
void solve()
{
	rep(i,0,n*m) rep(j,0,(1<<m)-1) dp[i][j]=0;
	dp[0][(1<<m)-1]=1;
	rep(i,0,n-1) rep(j,0,m-1) rep(k,0,(1<<m)-1)
	{
		int u=i*m+j+1;
		if (dp[u-1][k]==0) continue;
		if (j!=0&&a[i][j]==a[i][j-1]) 
		{
			int val=dp[u-1][k];
			if ((!(k&(1<<(j-1))))&&i!=0&&a[i][j-1]==a[i-1][j-1]) del(val,dp[u-2][k]);
			add(dp[u][k|(1<<j)|(1<<(j-1))],val);
		}
		if ((!(k&(1<<j)))&&i!=0&&a[i][j]==a[i-1][j]) add(dp[u][k],dp[u-1][k]);
		add(dp[u][k&(((1<<m)-1)^(1<<j))],dp[u-1][k]);
	}
}
int f[N][1<<17],g[1<<17],las[1<<17],R[1<<17];
int A[1<<17],B[1<<17],C[1<<17];
bool w[20];
void FWT(int *a,int tp)
{
	rep(j,0,m-1) rep(i,0,(1<<m)-1)
	{
		if (i&(1<<j)) 
		{
			if (tp==1) add(a[i],a[i^(1<<j)]);
			else del(a[i],a[i^(1<<j)]);
		}
	}
}
void fwt(int &ans)
{
	static int a[1<<17],b[1<<17],c[1<<17];
	rep(i,0,(1<<m)-1) a[i]=A[i],b[i]=B[i];
	FWT(a,1),FWT(b,1);
	rep(i,0,(1<<m)-1) c[i]=1ll*a[i]*b[i]%mod;
	FWT(c,-1);
	rep(i,0,(1<<m)-1) add(ans,1ll*c[i]*C[i]%mod);
}
void update(int &ans)
{
	fwt(ans);
}
void Reverse(int *a)
{
	static int b[1<<17];
	rep(i,0,(1<<m)-1) b[i]=a[i];
	rep(i,0,(1<<m)-1) a[i]=b[R[i]];
}
void initC()
{
	int z=0;
	rep(i,0,m-1) if (w[i]) z|=1<<i;
	rep(i,0,(1<<m)-1) C[i]=(1<<pcnt((((1<<m)-1)^i)&z));
}
void calc(int x,int y)
{
	int u=x*m+y+1,v=n*m-u;
	rep(i,0,(1<<m)-1) A[i]=dp[v][i],B[i]=g[i];
	Reverse(A);
	rep(i,0,m-1)
	{
		if (i<=y) 
		{
			if (x==n-1) w[i]=0;
			else w[i]=(a[x][i]==a[x+1][i]);
		}
		else
		{
			if (x==0) w[i]=0;
			else w[i]=(a[x][i]==a[x-1][i]);
		}
	}
	initC();
	update(ans[x][y]);
	if (y==m-1) return;
	if (a[x][y]!=a[x][y+1]) return;
	Reverse(A);
	
	int X=n-1-x,Y=m-2-y;
	rep(k,0,(1<<m)-1)
	{
		if ((!(k&(1<<Y)))&&X!=0&&a[n-1-X][m-1-Y]==a[n-1-(X-1)][m-1-Y]) del(A[k],dp[v-1][k]);
	}
	Reverse(A);
	rep(k,0,(1<<m)-1) del(B[k],las[k]);
	w[y]=0,w[y+1]=0;
	initC();
	update(ans[x][y]);
	
	
}
void work()
{
	rep(i,0,n*m) rep(j,0,(1<<m)-1) f[i][j]=0;
	f[0][(1<<m)-1]=1;
	rep(i,0,n-1) rep(j,0,m-1) 
	{
		rep(k,0,(1<<m)-1) g[k]=0;
		a[i][j]^=1;
		rep(k,0,(1<<m)-1)
		{
			int u=i*m+j+1;
			if (f[u-1][k]==0) continue;
			if (j!=0&&a[i][j]==a[i][j-1]) 
			{
				int val=f[u-1][k];
				if ((!(k&(1<<(j-1))))&&i!=0&&a[i][j-1]==a[i-1][j-1]) del(val,f[u-2][k]);
				add(g[k|(1<<j)|(1<<(j-1))],val);
			}
			las[k]=0;
			if ((!(k&(1<<j)))&&i!=0&&a[i][j]==a[i-1][j]) add(g[k],f[u-1][k]),las[k]=f[u-1][k];
			add(g[k&(((1<<m)-1)^(1<<j))],f[u-1][k]);	
		}
		calc(i,j);
		a[i][j]^=1;
		rep(k,0,(1<<m)-1)
		{
			int u=i*m+j+1;
			if (f[u-1][k]==0) continue;
			if (j!=0&&a[i][j]==a[i][j-1]) 
			{
				int val=f[u-1][k];
				if ((!(k&(1<<(j-1))))&&i!=0&&a[i][j-1]==a[i-1][j-1]) del(val,f[u-2][k]);
				add(f[u][k|(1<<j)|(1<<(j-1))],val);
			}
			if ((!(k&(1<<j)))&&i!=0&&a[i][j]==a[i-1][j]) add(f[u][k],f[u-1][k]);
			add(f[u][k&(((1<<m)-1)^(1<<j))],f[u-1][k]);	
		}
	}
}
int calc()
{
	int res=0;
	rep(i,0,(1<<m)-1) add(res,dp[n*m][i]);
	return res;
}

bool _ed;

int main()
{
	freopen("disanti.in","r",stdin);
	freopen("disanti.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cerr << (&_st-&_ed)/1024.0/1024 << endl;
	cin >> n >> m;
	rep(i,0,n-1) rep(j,0,m-1) a[i][j]=read();
	if (n<m)
	{
		rep(i,0,n-1) rep(j,0,m-1) b[i][j]=a[i][j];
		mem(a);
		rep(i,0,n-1) rep(j,0,m-1) a[j][i]=b[i][j];
		swap(n,m);
		flag=1;
	}
	rep(i,0,(1<<m)-1)
	{
		R[i]=R[i>>1]>>1;
		if (i&1) R[i]+=(1<<(m-1));
	}
	rotate();
	solve();
	rotate();
	work();
	if (flag==0)
	{
		rep(i,0,n-1) 
		{
			rep(j,0,m-1) cout << ans[i][j] << " ";
			cout << endl;
		}
	}
	else
	{
		rep(i,0,m-1) 
		{
			rep(j,0,n-1) cout << ans[j][i] << " ";
			cout << endl;
		}
	}
	return 0;
}
